/*
 * Created by Jaren at 2023/9/25 16:14
 */
import 'package:binary/binary.dart';
import 'package:inmotion_protocol/base/vehicle_data.dart';
import 'package:inmotion_protocol/elephant/bean/real_time_info.dart';
import 'package:inmotion_protocol/elephant/protocol.dart';
import 'package:inmotion_protocol/util/byte_util.dart';

class EHistoryStatistics extends HistoryStatistics {
  Int16 maxSpeed = Int16.zero;

  Uint16 mileage = Uint16.zero;
  Uint16 rideTime = Uint16.zero;

  @override
  int length() {
    return 0;
  }

  @override
  String toString() {
    return 'EHistoryStatistics{maxSpeed: $maxSpeed, mileage: $mileage, rideTime: $rideTime}';
  }

  void calculate(ERealTimeInfo realTimeInfo, StatisticsMocker statisticsMocker) {
    var tmpMaxSpeed = realTimeInfo.speed.value.abs();
    if (statisticsMocker.lastMaxSpeed < tmpMaxSpeed) {
      maxSpeed = ByteUtil.toInt16(realTimeInfo.speed.value);
      statisticsMocker.lastMaxSpeed = tmpMaxSpeed;
    } else {
      maxSpeed = ByteUtil.toInt16(statisticsMocker.lastMaxSpeed);
    }
  }
}

class ETotalStatistics extends TotalStatistics {
  Uint32 mileage = Uint32.zero;
  Uint32 rideTime = Uint32.zero;

  @override
  int length() {
    return 0;
  }

  @override
  String toString() {
    return 'ETotalStatistics{mileage: $mileage, rideTime: $rideTime}';
  }
}
